package com.caeit.controllers

import TestUserToken
import com.caeit.TestBase
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.web.context.WebApplicationContext

/**
 * 继承这个基类可以获取用户token
 */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest
@ExtendWith(SpringExtension::class)
class TestControllerBase : TestBase() {
    var adminToken = ""

    @Autowired
    lateinit var wac: WebApplicationContext
    lateinit var mvc: MockMvc

    @BeforeAll
    fun setUp() {
        mvc = MockMvcBuilders.webAppContextSetup(wac).build()
        val tut = TestUserToken()
        tut.testDoLogin()
        adminToken = tut.adminToken
    }

}